package com.zoe.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @Author Zoe
 * @Date: 2020/11/21
 * @Description
 */
public class Cat implements InitializingBean, DisposableBean, BeanNameAware, ApplicationContextAware {
    public Cat() {
        System.out.println("cat无参构造");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("cat被销毁==>DisposableBean.destroy()");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("cat==>InitializingBean.afterPropertiesSet()");
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("cat"+name+"==>BeanNameAware.setBeanName()");
    }

    public void init(){
        System.out.println("cat===>myInit");
    }

    public void myDestroy(){
        System.out.println("cat===>myDestroy");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("applicationContext.setApplicationContext()遍历容器开始===========");
        for (String beanDefinitionName : applicationContext.getBeanDefinitionNames()) {
            System.out.println(beanDefinitionName+"===>cat");
        }
        System.out.println("applicationContext.setApplicationContext()遍历容器结束===========");
    }
}
